package com;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class ServletDemo extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("fanwenjie");
        //req.getRequestDispatcher("index.jsp").forward(req, resp);

        resp.sendRedirect("first.jsp");

    }

    @Override
    public void destroy() {
        System.out.println("销毁");
    }

    @Override
    public void init(ServletConfig config) throws ServletException {
        config.getServletContext().setAttribute("name","fan");
        System.out.println(config.getServletContext().getAttribute("name"));
        System.out.println("servlet名字："+config.getServletName());
        ServletContext context = config.getServletContext();
        System.out.println("context路径："+context.getContextPath());
        System.out.println("属性："+context.getAttributeNames());
        System.out.println("初始化");
    }

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);

    }
}
